<template>
	<view class="page-container" style="background-color: #fafafa;">
		<!-- 顶部导航栏 -->
		<view class="header">
			<x-status-bar></x-status-bar>
			<view class="flex-center-between header-navbar">
				<x-back-btn></x-back-btn>
			</view>

			<view class="flex-center-between" style="padding: 0 30rpx 24rpx;">
				<view class="flex-center">
					<view class="u-avatar-66 clear-flex" style="width: 112rpx; height: 112rpx;">
						<image :src="showImage(dataInfo.imgUrl)" class="auto-img"></image>
					</view>
					<view class="flex-between flex-column u-m-l-30">
						<view class="u-f-44 u-lh-60 font-medio">{{ dataInfo.name || '' }}</view>
						<view class="u-f-32 u-lh-44 color-grew linecamp-1" style="width: 400rpx;">
							{{ dataInfo.jobTitle || '' }}
						</view>
					</view>
				</view>

				<view class="clear-flex nowrap">
					<x-common-btn width="154" height="62" background="#FD1E43">
						<view class="u-f-26 u-lh-36 font-medio" @click="changeAction">{{ lang_shop.subscribeNow }}
						</view>
					</x-common-btn>
				</view>
			</view>

			<view class="u-p-l-30 u-p-b-30 u-f-32 u-lh-44 linecamp-1">{{ dataInfo.desc || '' }}</view>

			<!-- 擅长项目 -->
			<view v-if="expertItems.length" class="expert-container bg-white">
				<u-gap height="5" bg-color="#fafafa"></u-gap>

				<scroll-view scroll-x>
					<view class="u-p-t-26 u-p-l-30 nowrap">
						<view v-for="(item, index) in expertItems" :key="index"
							:class="['tag-item u-m-b-22 u-m-r-12 color-grew']">
							{{ item }}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>


		<!-- 列表 -->
		<view>
			<mescroll-body :height="`calc(100vh - ${ expertItems.length ? 420 : 304 }rpx - var(--status-bar-height))`"
				ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view class="flex-between" style="padding: 20rpx 30rpx 0;">
					<view v-for="(list, lindex) in groups" :key="lindex" :class="[lindex > 0 ? 'u-p-l-18' : '']"
						style="width: calc(50%)">
						<view v-for="(item, index) in list" :key="index" class="u-m-b-20 bg-white"
							style="position: relative;width: 100%; border-radius: 8rpx; overflow: hidden;">
							<view :style="{
								width: '100%'
							}">
								<x-image :src="showImage(item.mediaUrl, 'logo')" mode="widthFix" style="max-height: 600rpx;"/>
							</view>
							<view class="linecamp-1" style="padding: 16rpx;">{{ item.title || '' }}</view>
						</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import waterfall from '@/utils/waterfall.js'
	import {
		merchantStaffWorkPage,
		merchantStaffInfo
	} from '@/api/user/merchant.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				merchantStaffId: '',
				dataInfo: {},
				leftRightHeight: [0, 0],
				groups: [
					[],
					[]
				],

				event: null
			}
		},
		computed: {
			expertItems() {
				let str = this.dataInfo.expertItems || ''
				let list = str.split(',') || []
				return list
			}
		},
		// 获取类型
		onLoad({
			merchantStaffId
		}) {
			this.merchantStaffId = merchantStaffId
			this.initInfo()
			this.event = this.getOpenerEventChannel()
		},
		methods: {
			// 点击立即预约后
			changeAction() {
				this.event.emit('changeAction')
				this.jumpBack()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef']
				merchantStaffWorkPage({
					pageNumber: page.num,
					pageSize: page.size,
					merchantStaffId: this.merchantStaffId
				}).then(res => {
					if (page.num == 1) {
						this.groups = [
							[],
							[]
						]
						this.leftRightHeight = [0, 0]
					}; //如果是第一页需手动制空列表
					waterfall({
						hs: this.leftRightHeight,
						list: res.list,
						key: 'mediaUrl'
					}, (hs, e) => {
						node && node.mescroll.endSuccess(res.list.length);
						this.leftRightHeight = hs
						this.groups = [
							[...this.groups[0], ...e[0]],
							[...this.groups[1], ...e[1]]
						]
					})
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef']
				node && node.mescroll.resetUpScroll()
			},
			// 获取商家员工详情
			initInfo() {
				merchantStaffInfo({
					merchantStaffId: this.merchantStaffId
				}).then((result) => {
					this.dataInfo = result
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.delete-btn {
		position: absolute;
		top: 14rpx;
		right: 14rpx;
		z-index: 1;
		width: 40rpx;
		height: 40rpx
	}

	.tag {
		&-item {
			display: inline-block;
			padding: 8rpx 36rpx;
			border: 2rpx solid #D5D5D5;
			border-radius: 100rpx;
		}
	}
</style>
